package jumpingnotes.model.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import net.jf.lucene.analysis.mmseg.MMSegAnalyzer;

import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;

@Entity
@Table(name = "chapter", catalog = "jumping_notes")
@Indexed
@Analyzer(impl = MMSegAnalyzer.class)
public class Chapter implements java.io.Serializable
{

	private Integer chapterId;
	private Book book;
	private int number;
	private String name;
	private String abstract_;
	private String uuid;
	private int memberId;
	private Date createTime;
	private Date updateTime;
	private Set<ChapterVersion> chapterVersions = new HashSet<ChapterVersion>(0);

	public Chapter()
	{
	}

	public Chapter(Book book, int number, String name, String uuid, int memberId, Date createTime)
	{
		this.book = book;
		this.number = number;
		this.name = name;
		this.uuid = uuid;
		this.memberId = memberId;
		this.createTime = createTime;
	}

	public Chapter(Book book, int number, String name, String abstract_, String uuid, int memberId, Date createTime,
			Date updateTime, Set<ChapterVersion> chapterVersions)
	{
		this.book = book;
		this.number = number;
		this.name = name;
		this.abstract_ = abstract_;
		this.uuid = uuid;
		this.memberId = memberId;
		this.createTime = createTime;
		this.updateTime = updateTime;
		this.chapterVersions = chapterVersions;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "chapter_id", unique = true, nullable = false)
	@DocumentId
	public Integer getChapterId()
	{
		return this.chapterId;
	}

	public void setChapterId(Integer chapterId)
	{
		this.chapterId = chapterId;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "book_id", nullable = false)
	public Book getBook()
	{
		return this.book;
	}

	public void setBook(Book book)
	{
		this.book = book;
	}

	@Column(name = "number", nullable = false)
	public int getNumber()
	{
		return this.number;
	}

	public void setNumber(int number)
	{
		this.number = number;
	}

	@Column(name = "name", nullable = false)
	@Field(index = Index.TOKENIZED, store = Store.NO)
	public String getName()
	{
		return this.name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	@Column(name = "abstract", length = 65535)
	@Field(index = Index.TOKENIZED, store = Store.NO)
	public String getAbstract_()
	{
		return this.abstract_;
	}

	public void setAbstract_(String abstract_)
	{
		this.abstract_ = abstract_;
	}

	@Column(name = "uuid", nullable = false)
	public String getUuid()
	{
		return this.uuid;
	}

	public void setUuid(String uuid)
	{
		this.uuid = uuid;
	}

	@Column(name = "member_id", nullable = false)
	public int getMemberId()
	{
		return this.memberId;
	}

	public void setMemberId(int memberId)
	{
		this.memberId = memberId;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "create_time", nullable = false, length = 19)
	public Date getCreateTime()
	{
		return this.createTime;
	}

	public void setCreateTime(Date createTime)
	{
		this.createTime = createTime;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "update_time", length = 19)
	public Date getUpdateTime()
	{
		return this.updateTime;
	}

	public void setUpdateTime(Date updateTime)
	{
		this.updateTime = updateTime;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "chapter")
	public Set<ChapterVersion> getChapterVersions()
	{
		return this.chapterVersions;
	}

	public void setChapterVersions(Set<ChapterVersion> chapterVersions)
	{
		this.chapterVersions = chapterVersions;
	}

}
